/*
* 提示类 createBy yongwang 2015/7/8
* */
(function(w){
    tip = {
        toast: function(str){
            if($("#toast").length == 0){
                var toast = document.createElement("div");
                toast.id = "toast";
                toast.className = "toast";
                document.body.appendChild(toast);

                //toast提示还原
                $("#toast")[0].addEventListener('webkitAnimationEnd', function(){
                    this.className = "toast";
                }, false);
            }

            $("#toast").text(str);
            $("#toast").addClass("toasts");
        },
        confirm: function(data){
            if($("#tip_confirm").length == 0){
                var confirm = document.createElement("div");
                confirm.id = "tip_confirm";
                confirm.className = "tip-confirm";
                confirm.innerHTML = "<div><div>"+data.str+"</div></div><div class = 'confirm-button'><span id = 'confirm_no'>取消</span><span id = 'confirm_yes'>确定</span></div>";
                document.body.appendChild(confirm);
                //$("#mask").css("display","block");

                $("#tip_confirm").delegate("#confirm_no,#confirm_yes","click",function(){
                    $("#tip_confirm").css("display","none");
                    if(this.id == "confirm_no"){
                        if(data.cancelMethod){
                            data.cancelMethod();
                        }
                        return false;
                    }else if(this.id == "confirm_yes"){
                        if(data.method){
                            data.method();
                        }
                    }
                });
            }else{
                $("#tip_confirm").css("display","block");
                $("#mask").css("display","block");
            }
        },
        roundLotteryTip: function(data){
            if($(".lottery-tip").length > 0){
                $("#lottery_tip_title").text("获得"+data.title);
                //$("#lottery_tip_content").addClass();
                $(".lottery-tip").css("display","block");
            }else{
                var html = "<div class = 'lottery-tip'>"+
                    "<div id = 'lottery_tip_title'>获得"+data.title+"</div>"+
                    "<div id = 'lottery_tip_content'></div>"+
                    "<div></div>"+
                    "</div>";
                $("body").append(html);
                $(document).on('touchend','#mask,.lottery-tip',function(e){
                    e.stopPropagation();
                    e.preventDefault();
                    $("#mask").css("display","none");
                    $(".lottery-tip").css("display","none");
                });
            }
            if(data.isReward){
                $("#lottery_tip_content").css("background","url('"+cw.resUrl+"/pages/roundLottery/images/get_reward-tip.png') no-repeat center");
                $("#lottery_tip_content").css("background-size","auto 100%");
            }else{
                $("#lottery_tip_content").css("background","url('"+cw.resUrl+"/pages/roundLottery/images/no_reward_tip.png') no-repeat center");
                $("#lottery_tip_content").css("background-size","auto 100%");
                //$("#lottery_tip_content")[0].style.background = "url('/pages/roundLottery/images/no_reward_tip.png') no-repeat center";
                //$("#lottery_tip_content")[0].style.backgroundSize = "auto 100%";
                $("#lottery_tip_title").text("");
            }
            $("#mask").css("display","block");
        },
        alert: function(data){
            if($(".alert").length > 0){
                //待扩展
                $(".alert").css("display","block");
            }else{
                var html = "<div class = 'alert'>"+
                    "<div id = 'alert_content'>"+data.content+"</div>"+
                    "<span id = 'alert_button'>关闭</span>"+
                    "</div>";
                $("body").append(html);
                $(document).on('touchend','#alert_button',function(e){
                    //$("#mask").css("display","none");
                    e.preventDefault();
                    $(".alert").css("display","none");
                });
                $(document).on('click','.alert',function(e){
                    e.preventDefault();
                });
            }

            //$("#mask").css("display","block");
        }
    };


    w.tip = tip;
}(window));